package com.example.hssmgs.Teacher;

import com.example.hssmgs.R;
import com.example.hssmgs.Student.CommonDatabase;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;




public class Teacher_look_stu extends Activity {
    Button go_back;
    Button find_msg;
    EditText edit_stu_id;
    SQLiteDatabase db;


    @SuppressLint("Range")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.teacher_look_stu);

        initView();

        final TextView s_about_account = findViewById(R.id.show_account_find);
        final TextView s_about_sname = findViewById(R.id.show_sname_find);
        final TextView s_about_age = findViewById(R.id.show_age_find);
        final TextView s_about_class = findViewById(R.id.show_class_find);
        final TextView s_about_sex = findViewById(R.id.show_sex_find);
        final TextView s_about_brith = findViewById(R.id.show_brith_find);
        final TextView s_about_clubInfo = findViewById(R.id.show_clubInfo_find);
        final TextView s_about_awards = findViewById(R.id.show_awards_find);
        final TextView s_about_work = findViewById(R.id.show_work_find);

        find_msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String student_id = edit_stu_id.getText().toString();
                @SuppressLint("Recycle") Cursor cursor_about = db.query("student_db",null,"id=?",new String[]{student_id},null,null,null);

                while(cursor_about.moveToNext())
                {
                    //将通过id查询到的学生信息显示到界面中
                    s_about_account.setText(cursor_about.getString(cursor_about.getColumnIndex("id")));
                    s_about_sname.setText(cursor_about.getString(cursor_about.getColumnIndex("sname")));
                    s_about_age.setText(cursor_about.getString(cursor_about.getColumnIndex("age")));
                    s_about_class.setText(cursor_about.getString(cursor_about.getColumnIndex("class")));
                    s_about_sex.setText(cursor_about.getString(cursor_about.getColumnIndex("sex")));
                    s_about_brith.setText(cursor_about.getString(cursor_about.getColumnIndex("brith")));
                    s_about_clubInfo.setText(cursor_about.getString(cursor_about.getColumnIndex("clubInfo")));
                    s_about_awards.setText(cursor_about.getString(cursor_about.getColumnIndex("awards")));
                    s_about_work.setText(cursor_about.getString(cursor_about.getColumnIndex("graduationWork")));
                }
                s_about_account.postInvalidate();
                s_about_sname.postInvalidate();
                s_about_age.postInvalidate();
                s_about_class.postInvalidate();
                s_about_sex.postInvalidate();
                s_about_brith.postInvalidate();
                s_about_clubInfo.postInvalidate();
                s_about_awards.postInvalidate();
                s_about_work.postInvalidate();
            }
        });



        go_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }

    private void initView() {
        go_back = findViewById(R.id.go_back_t);
        find_msg = findViewById(R.id.find_stu_bt);
        edit_stu_id = findViewById(R.id.find_stu_id);
        //获取数据库对象
        db = new CommonDatabase().getSqliteObject(Teacher_look_stu.this, "test2.db");
    }
}
